package com.mapbased.cc;

import org.dom4j.*;
import org.springframework.context.*;
import com.mapbased.wfw.*;
import com.mapbased.wfw.PageLoader.*;
import java.util.List;

/**
 * <p>Title: </p>
 *
 * <p>Description: fetch features from a binding </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class BindedFeatureTable
    extends FeatureTable
{

    Binding featuresBinding;
    /**
     *
     * @return FeatureMeta
     * @todo Implement this com.mapbased.cc.FeatureTable method
     */
    protected ApplicationContext getApplicationContext()
    {
        return null;
    }

    protected void fetchDataSource(Element ele,LoadContext loader)
    {
        Attribute a=ele.attribute("features");
        if(a == null)
        {
            throw new java.lang.RuntimeException(
                "Cannot find features attribute for BindedFeatureTable:" +
                ele.getName());
        }
        String s=a.getValue();
        ele.remove(a);

        LoadContext nlc=new LoadContext(loader);
        List l=nlc.segments;

        loader.loader.parseBinding(s,nlc);
        for(int i=0;i < l.size();i++)
        {
            Object o=l.get(i);
            if(o instanceof Binding)
            {
                this.featuresBinding=(Binding)o;
                break;

            }
        }
        if(this.featuresBinding == null)
        {
            throw new java.lang.RuntimeException(
                "Cannot find features binding for BindedFeatureTable!");
        }

    }

//    /**
//     * a component can choose to parse an element or not.
//     *
//     * @param ele Element
//     * @param lc PageLoader
//     * @return Element or null:if wanna page loader parse the
//     *   component,return the ele, else return null
//     * @todo Implement this com.mapbased.wfw.Component method
//     */
//    public Element parseXml(Element ele,LoadContext lc)
//    {
//        return super.parseXml(ele,lc);
//    }

    /**
     *
     * @param context RenderContext
     * @todo Implement this com.mapbased.cc.FeatureTable method
     */
    protected void prepareQuery(RenderContext context)
    {
    }

    protected void fillCol()
    {
        cols=new Col[]
            {};
    }

    protected List getFeatures(com.mapbased.wfw.RenderContext w)
    {
        return(List)this.featuresBinding.getValue(w);
    }
}
